/*
 * @package	educME
 * @copyright (c) Jose Raul Perez 2011 under GPL
 */
 
/* Decide what to do */
function main (checknum, iframe, url) {
    
    var action = parseUrl(url);
    var params = processQuery(action.query);
    
    switch (action.path) {
        
        case "/moodle/mod/assignment/view.php":
            assignment(checknum, iframe, params);
            break;
            
        default:
            // prevent click before load event
            iframe.block();
            iframe.setOpacity(0.5);
            
            surfTo(iframe, url);
            break;
    }
}

function surfTo (iframe, url) {
    // TODO prevent clicks before control the event
    
    var urlParsed = parseUrl(url);

    if (urlParsed.domain == "localhost") {
        if ( (urlParsed.protocol + "://" + urlParsed.domain + ":8888") != host()) {
            alert("UOPS!. Sorry, you can't leave moodle application ");
        } else {
            iframe.setSource(url);
        }
    } else {
        if ( (urlParsed.protocol + "://" + urlParsed.domain) != host() )
            alert("UOPS!. Sorry, you can't leave moodle application ");
        else
            iframe.setSource(url);

    }
    // don't go away !!    
}

